package com.yeban.javase.day17.sync;

import java.util.concurrent.TimeUnit;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/31
 */
public class Test {

    public static void main(String[] args) {
        House house = new House();

        Thread tA = new Thread(new Product(house), "生产者");
        tA.start();
        Thread tC = new Thread(new Product(house), "生产者");
        tC.start();

        Thread tB = new Thread(new Consumer(house), "消费者");
        tB.start();
        Thread tD = new Thread(new Consumer(house), "消费者");
        tD.start();

        int count = 15;
        while(count-- > 0) {
            try{
                TimeUnit.MILLISECONDS.sleep(200);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("---------- " + Thread.currentThread().getName() + " ----------");
            System.out.println("生产者A状态 = " + tA.getState());
            System.out.println("生产者C状态 = " + tC.getState());
            System.out.println("消费者B状态 = " + tB.getState());
            System.out.println("消费者D状态 = " + tD.getState());
            System.out.println();
        }
    }
}
